<html>
    <head>
        <style>
            body {
                padding: 0;
                margin: 0;
            }

            .screen {
                width: 100%;
                height: 100%;
                position: fixed;
                inset: 0;
                overflow: hidden;
            }

            .scroll {
                overflow-y: scroll;
            }

            #box {
                margin-top: 1000px;
                width: 100px;
                height: 100px;
                background-color: #0088ff;
            }

            #box-b {
                position: absolute;
                top: 100px;
                left: 100px;
                width: 200px;
                height: 200px;
                background-color: #0088ff;
            }

            [data-layout-correct="false"] {
                background: #dd1144 !important;
                opacity: 0.5;
            }
        </style>
    </head>
    <body>
        <div class="screen">
            <div id="box-b"></div>
        </div>

        <script type="module" src="/src/imports/projection.js"></script>
        <script type="module" src="/src/imports/script-assert.js"></script>
        <script type="module" src="/src/imports/script-undo.js"></script>
        <script type="module">
            const { createNode } = window.Undo
            const { matchViewportBox, matchVisibility, matchOpacity } =
                window.Assert
            const { frame } = window.Projection

            const screen = document.querySelector(".screen")
            const screenProjection = createNode(screen)

            const box = document.getElementById("box-b")
            const boxProjection = createNode(box, screenProjection, {
                layoutId: "box",
            })
            const boxOrigin = box.getBoundingClientRect()

            boxProjection.willUpdate()

            const scrollScreen = document.createElement("div")
            scrollScreen.classList.add("screen", "scroll")
            document.body.appendChild(scrollScreen)
            const newBox = document.createElement("div")
            newBox.id = "box"
            scrollScreen.appendChild(newBox)

            scrollScreen.scrollTop = 1000
            console.log(scrollScreen.scrollTop)
            const scrollScreenProjection = createNode(scrollScreen, undefined)
            const newBoxProjection = createNode(
                newBox,
                scrollScreenProjection,
                {
                    layoutId: "box",
                }
            )

            boxProjection.root.didUpdate()

            setTimeout(() => {
                matchViewportBox(box, boxOrigin)
                matchViewportBox(newBox, boxOrigin)
                matchViewportBox(box, newBox)
            }, 50)
        </script>
    </body>
</html>
